<template>
	<!-- 请假记录 -->
	<view class="records-container">
		<view class="content">
			
			<view class="item" @click="handleGoInfo(item)" v-for="(item,index) in recordsList" :key="index">
				<view class="top">
					<view class="top-1">申请人：{{ item.userName }}</view>
					<view class="bottom-1">{{ item.auditStatus_dictText }}</view>
				</view>
				<view class="bottom">
					<view class="bottom-1">请假时间：{{ item.startDate }} 至 {{ item.endDate }}</view>
					<view class="top-2">申请时间：{{ item.applyDate }}</view>
				</view>
			</view>
			
		</view>
		<u-loadmore :status="status" icon-color="#007AFF" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageNo:1,
				pageSize:10,
				status: 'loading',
				tolnum:0,
				recordsList:[]
			}
		},
		mounted() {
			this.getLeaveApply()
		},
		// 上拉
		onReachBottom() {
			this.pageNo = this.pageNo + 1
			if(this.pageNo > this.tolnum) {
				return this.status = 'nomore'
			}
			this.getLeaveApply()
		},
		// 下拉
		onPullDownRefresh() {
			this.recordsList=[]
			this.pageNo = 1;
			this.status = 'loading'
			this.getLeaveApply()
			setTimeout(function () {
			    uni.stopPullDownRefresh();
			}, 1500);
		},
		methods:{
			// 去详情
			handleGoInfo(item) {
				uni.setStorageSync('leaveItem',JSON.stringify(item))
				uni.navigateTo({
					url:'../AskForLeaveInfo/AskForLeaveInfo'
				})
			},
			// 获取列表
			getLeaveApply() {
				this.$u.api.getLeaveApply()
					.then(res => {
						console.log(res)
						if(res.code == 200) {
							this.tolnum = res.result.pages
							if (res.result.pages == 0) {
								this.status = 'nomore'
							}
							let list = res.result.records
							list.forEach(item => {
								this.recordsList.push(item)
							})
							this.status = 'nomore'
							if(this.pageNo == 1) {
								if(this.pageNo == this.tolnum) {
									this.status = 'nomore'
								}
							}
						}
					})
					.catch(err => {
						console.log(err)
						uni.showToast({
							title:'获取记录失败',
							icon:'none'
						})
						this.status = 'nomore'
					})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.records-container{
		background-color: #f5f6f7;
		min-height: 100vh;
		padding: 20rpx;
		.content{
			width: 100%;
			.item{
				width: 100%;
				background-color: #fff;
				border-radius: 15rpx;
				min-height: 190rpx;
				box-shadow: 0 5px 5px #eee,0 0 5px #eee,0 0 5px #eee;
				padding: 20rpx;
				display: flex;
				justify-content: space-around;
				align-items: center;
				flex-direction: column;
				margin-bottom: 30rpx;
				.top{
					width: 100%;
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 20rpx;
					.bottom-1:nth-child(2) {
						color: #d70505;
						font-weight: 600;
						text-align: right;
					}
					.top-1{
						font-size: 27rpx;
						color: #333;
						font-weight: 600;
					}
					.top-2{
						color: #999;
						font-size: 26rpx;
					}
				}
				.bottom{
					width: 100%;
					.bottom-1:nth-child(2) {
						color: #d70505;
						font-weight: 600;
						text-align: right;
					}
					.bottom-1{
						text-align: left;
						color: #999;
						font-size: 26rpx;
						padding: 10rpx 0;
					}
					.top-2{
						color: #999;
						font-size: 26rpx;
					}
				}
			}
		}
	}
</style>
